package org.game.db.bean;

import static org.game.db.StaticResource.ServerMailResource.PINGYING_COLUMN_NAMES;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import static org.game.db.StaticResource.ServerMailResource.COLUMN_COUNT;
import org.apache.commons.lang3.ArrayUtils;
import java.sql.SQLException;
import static org.game.db.StaticResource.ServerMailResource.FK_SOURCE_TABLE_NAMES;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import java.sql.ResultSet;
import java.util.Map;
import static org.game.db.StaticResource.ServerMailResource.FK_PINGYING_COLUMN_NAMES;
import static org.game.db.StaticResource.ServerMailResource.SOURCE_COLUMN_REMARKS;
import static org.game.db.StaticResource.ServerMailResource.COLUMN_BASICTYPES;
import static org.game.db.StaticResource.ServerMailResource.*;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.ServerMailResource.FK_HASHCODE_COLUMN_NAMES;
import com.sojoys.artifact.build.data.base.BasePojo;
import static org.game.db.StaticResource.ServerMailResource.HASHCODE_COLUMN_NAMES;
import static org.game.db.StaticResource.ServerMailResource.FK_PINGYING_TABLE_NAMES;
import static org.game.db.StaticResource.ServerMailResource.SOURCE_COLUMN_NAMES;
import com.sojoys.artifact.tools.ToolCopy;
import static org.game.db.StaticResource.ServerMailResource.FK_SOURCE_COLUMN_NAMES;
import org.game.db.cache.ServerMailCache;
import com.alibaba.fastjson.JSONObject;
import static org.game.db.StaticResource.ServerMailResource.FK_HASHCODE_TABLE_NAMES;
import static org.game.db.StaticResource.ServerMailResource.COLUMN_CLASSTYPES;
import static org.game.db.StaticResource.ServerMailResource.COLUMN_COLUMNTYPES;
import static org.game.db.StaticResource.ServerMailResource.*;
/**
 * 全服邮件
 */
public class ServerMail extends BasePojo<ServerMail> implements org.game.db.vo.BaseMail{
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 全服邮件唯一ID
	*/
	private String uniqueId;
	
	/**
	* 发送者
	*/
	private int senderId;
	
	/**
	* 文字类型
	*/
	private int textType;
	
	/**
	* 标题
	*/
	private String title;
	
	/**
	* 内容
	*/
	private String body;
	
	/**
	* 附件
	*/
	private Map items;
	
	/**
	* 玩家状态
	*/
	private Map pidsStatus;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static ServerMail builder() {
		ServerMail serverMail = new ServerMail();
		return serverMail;
	}
	
	@Deprecated
	public ServerMail() {
		super();
	}
	
	public ServerMail(int id, String uniqueId, int senderId, int textType, String title, String body, Map items, Map pidsStatus) {
		super();
		this.id = id;
		this.uniqueId = uniqueId;
		this.senderId = senderId;
		this.textType = textType;
		this.title = title;
		this.body = body;
		this.items = items;
		this.pidsStatus = pidsStatus;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public ServerMail setId(int id) {this.id = id;return this;}
	
	/**
	 * 全服邮件唯一ID
	 */
	public String getUniqueId() {return uniqueId;}
	
	/**
	 * 全服邮件唯一ID
	 */
	public ServerMail setUniqueId(String uniqueId) {this.uniqueId = uniqueId;return this;}
	
	/**
	 * 发送者
	 */
	public int getSenderId() {return senderId;}
	
	/**
	 * 发送者
	 */
	public ServerMail setSenderId(int senderId) {this.senderId = senderId;return this;}
	
	/**
	 * 文字类型
	 */
	public int getTextType() {return textType;}
	
	/**
	 * 文字类型
	 */
	public ServerMail setTextType(int textType) {this.textType = textType;return this;}
	
	/**
	 * 标题
	 */
	public String getTitle() {return title;}
	
	/**
	 * 标题
	 */
	public ServerMail setTitle(String title) {this.title = title;return this;}
	
	/**
	 * 内容
	 */
	public String getBody() {return body;}
	
	/**
	 * 内容
	 */
	public ServerMail setBody(String body) {this.body = body;return this;}
	
	/**
	 * 附件
	 */
	public Map getItems() {return items;}
	
	/**
	 * 附件
	 */
	public ServerMail setItems(Map items) {this.items = items;return this;}
	
	/**
	 * 附件
	 */
	public byte[] getItemsByte() {
		return toBytes(items);
	}
	
	/**
	 * 附件
	 */
	public Map initItemsByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * 玩家状态
	 */
	public Map getPidsStatus() {return pidsStatus;}
	
	/**
	 * 玩家状态
	 */
	public ServerMail setPidsStatus(Map pidsStatus) {this.pidsStatus = pidsStatus;return this;}
	
	/**
	 * 玩家状态
	 */
	public byte[] getPidsStatusByte() {
		return toBytes(pidsStatus);
	}
	
	/**
	 * 玩家状态
	 */
	public Map initPidsStatusByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected ServerMail setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected ServerMail setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.uniqueId;
        values[2] = this.senderId;
        values[3] = this.textType;
        values[4] = this.title;
        values[5] = this.body;
        values[6] = this.items;
        values[7] = this.pidsStatus;
        values[8] = this.createDate;
        values[9] = this.modifiedDate;
        return values;
	}
	
	public ServerMail deepCopy(){
		ServerMail serverMail = null;
		try {
			serverMail = (ServerMail) super.clone();
		    serverMail.setItems(ToolCopy.copyObject(this.items));
		    serverMail.setPidsStatus(ToolCopy.copyObject(this.pidsStatus));
		    serverMail.setCreateDate(ToolCopy.copyObject(this.createDate));
		    serverMail.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    serverMail.indexValues = ArrayUtils.clone(indexValues);
			return serverMail;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return serverMail;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.uniqueId);
        map.put(keys[2], this.senderId);
        map.put(keys[3], this.textType);
        map.put(keys[4], this.title);
        map.put(keys[5], this.body);
        map.put(keys[6], this.items);
        map.put(keys[7], this.pidsStatus);
        map.put(keys[8], this.createDate);
        map.put(keys[9], this.modifiedDate);
        return map;
    }
    
    protected ServerMail createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.uniqueId = (String)map.get(keys[1]);
   		this.senderId = (int)map.get(keys[2]);
   		this.textType = (int)map.get(keys[3]);
   		this.title = (String)map.get(keys[4]);
   		this.body = (String)map.get(keys[5]);
   		this.items = (Map)map.get(keys[6]);
   		this.pidsStatus = (Map)map.get(keys[7]);
   		this.createDate = (java.util.Date)map.get(keys[8]);
   		this.modifiedDate = (java.util.Date)map.get(keys[9]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.uniqueId);
        obj.put(keys[2], this.senderId);
        obj.put(keys[3], this.textType);
        obj.put(keys[4], this.title);
        obj.put(keys[5], this.body);
        obj.put(keys[6], toBytes(items));
        obj.put(keys[7], toBytes(pidsStatus));
        obj.put(keys[8], this.createDate);
        obj.put(keys[9], this.modifiedDate);
        return obj;
    }
    
    protected ServerMail createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.uniqueId = obj.getString(keys[1]);
	    this.senderId = obj.getIntValue(keys[2]);
	    this.textType = obj.getIntValue(keys[3]);
	    this.title = obj.getString(keys[4]);
	    this.body = obj.getString(keys[5]);
		this.items = (Map)forBytesObject(obj.getBytes(keys[6]));
		this.pidsStatus = (Map)forBytesObject(obj.getBytes(keys[7]));
	    this.createDate = obj.getDate(keys[8]);
	    this.modifiedDate = obj.getDate(keys[9]);
        return this;
    }
    
    
    public ServerMail createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.uniqueId = rs.getString(SOURCE_COLUMN_NAMES[1]);
	    this.senderId = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.textType = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.title = rs.getString(SOURCE_COLUMN_NAMES[4]);
	    this.body = rs.getString(SOURCE_COLUMN_NAMES[5]);
		this.items = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[6]));
		this.pidsStatus = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[7]));
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[8]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[9]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeString(this.uniqueId);
	    byteBuf.writeInt(this.senderId);
	    byteBuf.writeInt(this.textType);
	    byteBuf.writeString(this.title);
	    byteBuf.writeString(this.body);
	    byteBuf.writeObject(this.items);
	    byteBuf.writeObject(this.pidsStatus);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected ServerMail readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.uniqueId = byteBuf.readString(null);
	    this.senderId = byteBuf.readInt(null);
	    this.textType = byteBuf.readInt(null);
	    this.title = byteBuf.readString(null);
	    this.body = byteBuf.readString(null);
	    this.items = (Map)byteBuf.readObject();
	    this.pidsStatus = (Map)byteBuf.readObject();
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public ServerMail insert(){
    	return ServerMailCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public ServerMail update(){
    	return ServerMailCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return ServerMailCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public ServerMail insertAndFlush(){
    	return ServerMailCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public ServerMail updateAndFlush(){
    	return ServerMailCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return ServerMailCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public ServerMail syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getUniqueId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}